package com.spring.demo.webflux.demo.handler;

import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;

/**
 * @author wangzhilong
 * @date 2020/7/7
 */
@Component
public class CityHandler {

    /**
     * 基于功能端点的实现  配合 Router实现
     * ServerResponse是对响应的封装，可以设置响应状态，响应正文。比如ok代表200响应码
     * MediaType枚举代表这个文本内容类型，返回的是String对象
     * @param request
     * @return
     */
    public Mono<ServerResponse> helloCity(ServerRequest request) {
        return ServerResponse.ok().contentType(MediaType.TEXT_PLAIN)
                .body(BodyInserters.fromValue("hello ,City!"));
    }

}
